Skip to content

Refactor: Standardize PackageManager #1538

Open
edvilme wants to merge 15 commits into
mainfrom
vscode-python-environments-package-refactor
Open

Refactor: Standardize PackageManager #1538
edvilme wants to merge 15 commits into
mainfrom
vscode-python-environments-package-refactor

Conversation

@edvilme
Copy link
Copy Markdown
Contributor

@edvilme edvilme commented May 21, 2026

This pull request introduces a new GetPackagesOptions interface to support additional options (such as cache bypassing) when retrieving Python packages from a given environment. It updates the relevant APIs, interfaces, and implementations to accept this new options parameter, and refactors the pip package manager logic to support cache skipping and code simplification. The changes are applied consistently across the main codebase and sample/example files.

API and Interface Enhancements:

  • Added a new GetPackagesOptions interface, allowing callers to specify options (currently skipCache) when retrieving packages. This is now accepted by getPackages methods in PackageManager and PythonPackageGetterApi interfaces. [1] [2] [3] [4] [5] [6] [7] [8]

  • Updated all usages and implementations of getPackages to accept the new optional options parameter, including in PythonEnvironmentApiImpl, InternalPackageManager, and related example/sample APIs. [1] [2] [3] [4]

Pip Package Manager Refactoring and Improvements:

  • Renamed pipManager.ts to pipPackageManager.ts and updated imports accordingly.

  • Refactored the pip package manager to support cache bypassing: if options.skipCache is set, it fetches a fresh package list instead of using the cache. Also simplified the logic for managing and refreshing packages, delegating change notification to a new shared utility. [1] [2] [3]

  • Removed redundant code for change detection and replaced with a shared updatePackagesAndNotify utility. [1] [2] [3]

Utilities and Supporting Changes:

  • Refactored pip package refresh utilities: replaced the raw refresh logic with a more flexible function (execPipList) that supports additional arguments, and removed now-unnecessary helper functions. [1] [2] [3] [4]

Code Style and Minor Cleanups:

  • Minor formatting and code style updates across example/sample API files for consistency. [1] [2] [3] [4] [5] [6] [7]

These changes improve the flexibility and maintainability of the package management APIs and their implementations, preparing the codebase for future enhancements and better cache control.

@edvilme edvilme requested a review from Copilot May 21, 2026 22:37
@edvilme edvilme changed the title Refactor: PackageManager interface Refactor: Standardize PackageManager May 21, 2026
@edvilme edvilme added debt Code quality issues no-changelog labels May 21, 2026

This comment was marked as resolved.

@edvilme edvilme force-pushed the vscode-python-environments-package-refactor branch 2 times, most recently from ce7e024 to fc73d95 Compare May 21, 2026 23:21
@edvilme edvilme requested a review from Copilot May 21, 2026 23:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Comment thread src/managers/common/packageChanges.ts
Comment thread src/test/managers/common/packageChanges.unit.test.ts
@edvilme
Copy link
Copy Markdown
Contributor Author

edvilme commented May 22, 2026

These refactorings make adding new features to the Package Managers (e.g., #1530) much easier by properly delegating responsibilities and using clear API names.

@eleanorjboyd
Copy link
Copy Markdown
Member

This one I will need to consider more as they adjust the api surface. I would be more comfortable with a change where we instead added an optional arg to the get or manage packages that allowed you to specify if it should refresh cache. So we have the same surface generally just allows someone to specify what type of change it should be as it relates to the cache. What are your thoughts on a design like this?

@edvilme edvilme force-pushed the vscode-python-environments-package-refactor branch from 9d57c50 to 986e84a Compare May 27, 2026 23:44
@edvilme edvilme force-pushed the vscode-python-environments-package-refactor branch from 3eefeef to 03cd8f0 Compare May 28, 2026 23:19
@eleanorjboyd eleanorjboyd requested a review from Copilot May 29, 2026 18:45
Comment thread api/src/main.ts
* When `true`, bypasses the cache and fetches the latest packages from the underlying tool.
* Defaults to `false`.
*/
skipCache?: boolean;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the point of going with options that then has the skipCache inside is just more flexibility down the line? Did you have anything else in mind you were going to put into this object?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for flexibility down the line. Perhaps adding an option for overriding the feed, or perhaps specifying some filter

@eleanorjboyd
Copy link
Copy Markdown
Member

just the one question but overall looks good!!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 14/14 changed files
  • Comments generated: 4

Comment thread src/managers/conda/condaUtils.ts Outdated
Comment thread src/managers/common/packageChanges.ts Outdated
Comment thread src/api.ts
Comment thread src/test/managers/common/packageChanges.unit.test.ts
await this.refresh(environment);
async getPackages(environment: PythonEnvironment, options?: GetPackagesOptions): Promise<Package[] | undefined> {
if (options?.skipCache || !this.packages.has(environment.envId.id)) {
const packages = await this.fetchPackagesFromTool(environment);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be handled more elegantly? The old getPackage calls refresh() that shows a friendly error not blocking UI, this one will just throw an uncaught exception.

if (!this.packages.has(environment.envId.id)) {
await this.refresh(environment);
async getPackages(environment: PythonEnvironment, options?: GetPackagesOptions): Promise<Package[] | undefined> {
if (options?.skipCache || !this.packages.has(environment.envId.id)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all old getPackages are wrapped in withProgress in refresh, any reason why they are got rid of now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flow goes refresh() -> updatePackagesAndNotify() -> getPackages()
Refresh handles the withProgress and exception catching
updatePackagesAndNotify centralizes the updating (also makes marking packages as (in)transitive easier

@edvilme edvilme requested a review from eleanorjboyd May 29, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debt Code quality issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants